package com.tanhua.dubbodb.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.model.domain.BlackList;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.dubbodb.mapper.BlackListMapper;
import com.tanhua.dubbodb.mapper.UserInfoMapper;
import com.tanhua.dubbointerface.api.BlackListApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;
    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 分页查询，因为要查出黑名单中的人的具体信息，所以需要两表联查，要用到UserInfo表
     * @param userId
     * @param page
     * @param pagesize
     * @return
     */
    @Override
    public IPage<UserInfo> getPage(Long userId, int page, int pagesize) {
        Page pages = new Page(page,pagesize);
        IPage<UserInfo> blackList = userInfoMapper.findBlackList(pages, userId);
        return blackList;
    }

    /**
     * 获得BlackList对象
     *
     * @return
     */

    @Override
    public BlackList findByUserId(Long uid) {
        QueryWrapper<BlackList> q = new QueryWrapper<>();
        q.eq("black_user_id",uid);
        BlackList blackList = blackListMapper.selectOne(q);
        return blackList;
    }


}
